function saveGMM(filename, mix)

% save a netlab gmm struct into a textfile that has the same format as Fabrice's Clustering code

fileid = fopen(filename, 'wt');

fprintf(fileid, '%d\n', mix.ncentres);
for i = 1:mix.ncentres
    fprintf(fileid, ['%d' repmat(' %.30g', 1, mix.nin) '\n'], [mix.nin mix.centres(i, :)]);
    fprintf(fileid, '%d %d\n', [mix.nin mix.nin]);
    for j = 1:mix.nin
        fprintf(fileid, [repmat('%.30g ', 1, mix.nin-1) '%.30g' '\n'], mix.covars(j, :, i));
    end
    fprintf(fileid, '%.30g\n', mix.priors(i));
end

fclose('all');
